//
//  GTIssue.swift
//  GitOSC-Swift
//
//  Created by 李萍 on 16/3/10.
//  Copyright © 2016年 李萍. All rights reserved.
//

import UIKit
import SwiftyJSON

class GTIssue: NSObject {
    var issueID: Int!
    var issueIid: Int!
    var projectId: Int!
    var title: String!
    var issueDescription: String!
    
    var assignee: GTUser!
    var author: GTUser!
    var state: String!
    var updatedAt: String!
    var createdAt: String!
    
    init(json: JSON) {
        issueID = json["id"].intValue
        issueIid = json["iid"].intValue
        projectId = json["project_id"].intValue
        title = json["title"].stringValue
        issueDescription = json["description"].stringValue
        
        assignee = GTUser.init(json: json["assignee"])
        author = GTUser.init(json: json["author"])
        state = json["state"].stringValue
        updatedAt = json["updated_at"].stringValue
        createdAt = json["created_at"].stringValue
        
    }
    
    func setUserNameAndTime() -> String {
        let time = createdAt.substringToIndex(createdAt.startIndex.advancedBy(10))
        return "#\(issueIid) by \(author.name) - \(time)"
    }
}
